//
//  WorkSummaryCommentCell.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 16/12/23.
//  Copyright © 2016年 com.xtion.crm. All rights reserved.
//

#import "WorkSummaryCommentCell.h"

#define HeadImageSize       45

#define BorderLeftRightMargin        10

#define ControlLeftRightMargin          10

#define ControlTopBottomMargin          10

@interface WorkSummaryCommentCell()
{
    UILabel *_createUserLabel;
    UILabel *_createTimeLabel;
    UILabel *_commentContentLabel;
    
    UILabel *_lineLabel;
}
@end

@implementation WorkSummaryCommentCell

-(instancetype)init
{
    return [self initWithFrame:CGRectZero];
}

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    _createUserLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, BorderLeftRightMargin, 200, 20)];
    _createUserLabel.backgroundColor = [UIColor clearColor];
    _createUserLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_createUserLabel];
    
    _createTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _createUserLabel.top, 120, 20)];
    _createTimeLabel.backgroundColor = [UIColor clearColor];
    _createTimeLabel.font = [UIFont systemFontOfSize:13];
    _createTimeLabel.textColor = [UIColor grayColor];
    _createTimeLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_createTimeLabel];
    
    _lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _createUserLabel.bottom + ControlTopBottomMargin, 0, 0.5)];
    _lineLabel.backgroundColor = [UIColor grayColor];
    _lineLabel.alpha = 0.2;
    [self.contentView addSubview:_lineLabel];
    
    _commentContentLabel = [[UILabel alloc]initWithFrame:CGRectMake(BorderLeftRightMargin, 0, 0, 20)];
    _commentContentLabel.backgroundColor = [UIColor clearColor];
    _commentContentLabel.font = [UIFont systemFontOfSize:16];
    _commentContentLabel.numberOfLines = 0;
    _commentContentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self.contentView addSubview:_commentContentLabel];
    
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _createTimeLabel.right = self.contentView.right - BorderLeftRightMargin;
    
    _lineLabel.width = self.contentView.width;
    
    CGFloat width = self.contentView.width - BorderLeftRightMargin - BorderLeftRightMargin;
    CGFloat left = BorderLeftRightMargin;
    CGSize contentSize = [_commentContentLabel.text wrapStringSizeWithFont:_commentContentLabel.font forWidth:width];
    _commentContentLabel.frame = CGRectMake(left, _lineLabel.bottom + ControlTopBottomMargin, width, contentSize.height);
}

+(CGFloat)caleHeight:(CGFloat)containWidth content:(NSString*)content
{
    CGFloat height = 0 ;
    
    height = BorderLeftRightMargin;
    height += 20;
    height += ControlTopBottomMargin;
    
    height += ControlTopBottomMargin;
    CGFloat width = containWidth - BorderLeftRightMargin - BorderLeftRightMargin;
    height += [content wrapStringSizeWithFont:[UIFont systemFontOfSize:16] forWidth:width].height;
    height += ControlTopBottomMargin;
    
    height += 0.5;
    
    return height;
}

- (void)setCreateUser:(NSString *)createUser
{
    _createUserLabel.text = createUser;
}

- (void)setCreateTime:(NSString *)createTime
{
    _createTimeLabel.text = createTime;
}

- (void)setCommentContent:(NSString *)commentContent
{
    _commentContentLabel.text = commentContent;
}
@end
